package com.gnerv.pabu.basic.core.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gnerv.pabu.basic.core.entity.Result;
import com.gnerv.pabu.basic.core.service.INoticeService;
import com.gnerv.pabu.basic.core.dto.NoticeDTO;
import com.gnerv.pabu.basic.core.dto.NoticeSaveDTO;
import com.gnerv.pabu.basic.core.dto.NoticeSearchDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 基础平台-通知公告表(ManageNotice)表控制层
 *
 * @author makejava
 * @since 2020-03-04 23:01:03
 */
@Api(tags = "通知公告")
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api/manage/notice")
public class NoticeController {
    
    @Resource
    private INoticeService noticeService;



    @ApiOperation(value = "保存 通知公告")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result saveNotice(@RequestBody NoticeSaveDTO noticeSaveDTO) {
        noticeService.saveNotice(noticeSaveDTO);
        return Result.response();
    }

    @ApiOperation(value = "新建 通知公告")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Result createNotice(@RequestBody NoticeSaveDTO noticeSaveDTO) {
        noticeService.createNotice(noticeSaveDTO);
        return Result.response();
    }

    @ApiOperation(value = "删除 通知公告")
    @RequestMapping(value = "/delete/{noticeId}", method = RequestMethod.GET)
    public Result deleteByNoticeId(@PathVariable(value = "noticeId") String noticeId) {
        noticeService.deleteByNoticeId(noticeId);
        return Result.response();
    }

    @ApiOperation(value = "修改 通知公告")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result updateNotice(@RequestBody NoticeSaveDTO noticeSaveDTO) {
        noticeService.updateNotice(noticeSaveDTO);
        return Result.response();
    }

    @ApiOperation(value = "查询 通知公告")
    @RequestMapping(value = "/select/{noticeId}", method = RequestMethod.GET)
    public Result selectByNoticeId(@PathVariable(value = "noticeId") String noticeId) {
        NoticeDTO notice = noticeService.selectByNoticeId(noticeId);
        return Result.response().data("notice", notice);
    }


    @ApiOperation(value = "修改 通知公告状态")
    @RequestMapping(value = "/{noticeId}/status/{status}", method = RequestMethod.GET)
    public Result updateNoticeStatus(@PathVariable(value = "noticeId") String noticeId,
                                         @PathVariable(value = "status") Integer status) {
        noticeService.updateNoticeStatus(noticeId, status);
        return Result.response();
    }


    @ApiOperation(value = "查询通知公告列表 带分页 支持模糊查询")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result listNotice(NoticeSearchDTO notice,
                                 @RequestParam(value = "current", defaultValue = "1") Long current,
                                 @RequestParam(value = "size", defaultValue = "300") Long size) {
        Page<NoticeDTO> notices = noticeService.listNotice(notice, current, size);
        return Result.response().data("notices", notices);
    }
    
}